package com.community.service.repair;


import com.community.entity.ContactRoom;
import com.community.entity.RepairItem;
import com.community.entity.Result;
import com.community.mapper.repair.RepairMapper;
import com.community.mapper.room.RoomMapper;
import com.community.utils.Repair;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class RepairService {

    @Autowired
    private RepairMapper repairMapper;

    @Autowired
    private RoomMapper roomMapper;

    public void modifyStatus(String id, String status) {

        repairMapper.modifyStatus(id, Integer.parseInt(status));
    }


    public void addRepair(String uuid, String houseId, String description, String mobile, String repairItemId, Date appointment) {
        String repairItemName = Repair.getRepairName(repairItemId);
        ContactRoom room = roomMapper.getRoomName(houseId);
        String houseInfo = room.getName();
        log.info("维修的项目名称为:{}", repairItemName);
        repairMapper.addRepair(uuid, houseId, houseInfo, description, mobile, repairItemId,repairItemName, appointment);
    }

    public void editRepair(String id, String houseId, String description, String mobile, String repairItemId, Date appointment) {
        String repairItemName = Repair.getRepairName(repairItemId);
        log.info("编辑的项目名称为:{}", repairItemName);
        repairMapper.editRepair(id, description, mobile, repairItemId, repairItemName, appointment);
    }

    public com.community.entity.Repair getDetails(String id) {

        return repairMapper.getDetails(id);
    }

    public List<RepairItem> getRepairItem() {
        return repairMapper.getRepairItem();
    }

    public void cancelRepair(String id) {
        repairMapper.cancelRepair(id);
    }
}
